<template>
	<view class="">
		<tn-nav-bar fixed :bottomShadow="false">
			模板</tn-nav-bar>
		<view v-if="list.length!==0" class="discovery tn-safe-area-inset-bottom" :style="{MarginTop: vuex_custom_bar_height + 'px'}">
			<view class="">
				<view class="" style="padding: 30rpx 20rpx;">

					<tn-waterfall ref="waterfall" v-model="list" @finish="handleWaterFallFinish">
						<template v-slot:left="{ leftList }">
							<view v-for="(item, index) in leftList" :key="item.id" class="product__item"
								@click="tn(`/circlePages/details/details?id=${item.id}`)">
								<view class="item__image ">
									<tn-lazy-load :threshold="-450" height="100%" :image="item.icon" :index="item.id"
										imgMode="widthFix"></tn-lazy-load>
								</view>
								<view class="item__data">
									<view class="item__title-container">
										<!-- <view v-if="item.newProduct" class="item__store-type tn-bg-gray--light">标签</view>
		                <view v-else-if="item.storeType === 1" class="item__store-type tn-cool-bg-color-1">SVIP</view> -->
										<text class="item__title tn-color-cat">{{ item.name}}</text>
									</view>
									<!--  <view v-if="item.tags && item.tags.length > 0" class="item__tags-container">
		                <view v-for="(tagItem, tagIndex) in item.tags" :key="tagIndex" class="item__tag">{{ tagItem }}</view>
		              </view> -->

									<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding-top-xs">
										<view class="justify-content-item">
											<view class="tn-flex tn-flex-col-center tn-flex-row-left">
												<view class="logo-pic">
													<!-- 	<view class="logo-image">
														<view class=""
															:style="'background-image:url('+ item.userImage +');width: 40rpx;height: 40rpx;background-size: cover;'">
														</view>
													</view> -->
												</view>
												<view class="tn-padding-left-xs">
													<text class="tn-color-gray tn-text-sm">{{ item.biaoqian }}</text>
												</view>

											</view>
										</view>
										<view class="justify-content-item">
											<text class="tn-icon-rocket tn-color-gray tn-padding-right-xs"></text>
											<text class="tn-color-gray">编辑</text>
										</view>
									</view>


								</view>
							</view>
						</template>
						<template v-slot:right="{ rightList }">
							<view v-for="(item, index) in rightList" :key="item.id" class="product__item matop"
								@click="tn(`/circlePages/details/details?id=${item.id}`)">
								<view class="item__image">
									<tn-lazy-load :threshold="-450" height="100%" :image="item.icon" :index="item.id"
										imgMode="widthFix"></tn-lazy-load>
								</view>
								<view class="item__data">
									<view class="item__title-container">
										<!-- <view v-if="item.storeType === 1" class="item__store-type tn-cool-bg-color-5">VIP</view> -->
										<text class="item__title tn-color-cat">{{ item.name }}</text>
									</view>
									<!-- 	<view class="item__tags-container">
										<view v-for="(tagItem, tagIndex) in item.tags" :key="tagIndex"
											class="item__tag">{{ tagItem }}</view>
									</view> -->
									<!-- <view class="item__price-container">
		                <text class="item__price--unit">￥</text>
		                <text class="item__price--integer">{{ item.priceInteger }}</text>
		                <text class="item__price--dot">.</text>
		                <text class="item__price--decimal">{{ item.priceDecimal }}</text>
		              </view> -->
									<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding-top-xs">
										<view class="justify-content-item">
											<view class="tn-flex tn-flex-col-center tn-flex-row-left">
												<view class="logo-pic">
													<!-- 	<view class="logo-image">
														<view class=""
															:style="'background-image:url('+ item.userImage +');width: 40rpx;height: 40rpx;background-size: cover;'">
														</view>
													</view> -->
												</view>
												<view class="tn-padding-left-xs">
													<text class="tn-color-gray tn-text-sm">{{ item.biaoqian }}</text>
												</view>

											</view>
										</view>
										<view class="justify-content-item">
											<text class="tn-icon-rocket tn-color-gray tn-padding-right-xs"></text>
											<text class="tn-color-gray">编辑</text>
										</view>
									</view>
								</view>
							</view>
						</template>
					</tn-waterfall>
				</view>
					<tn-load-more :status="loadStatus" v-if="list.length!==0"></tn-load-more>
			</view>
		</view>
		<view class="" v-else :style="{MarginTop: vuex_custom_bar_height + 'px'}">
			<view class="" style="padding: 30rpx 20rpx;">
				<view class="tn-text-center" style="font-size: 200rpx;padding-top: 30rpx;">
					<text class="tn-icon-wea-wind tn-color-gray--light"></text>
				</view>
				<view class="tn-color-gray--disabled tn-text-center tn-text-lg">暂无模板</view>
			</view>
		</view>
	
	</view>

</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import  {getmodulelist} from '@/api/home/index.js'
	export default {
		mixins: [template_page_mixin],
		data() {
			return {
				//当前页
				current_page: 1,
				//最后
				last_page: '',
				//数据
				moduleList: [],
				//瀑布数据
				list: [],
				/* 瀑布流*/
				loadStatus: 'loadmore',
				current:1
			}
		},
		onLoad(e) {
			if(!e.search){
				this.modulelist(e.categoryId, e.erjifenlei)
			}else{
				this.modulelist(e.categoryId, e.erjifenlei, e.search)
			}

		},
		onShow() {},
		onPullDownRefresh() {
		},
		onReachBottom() {
			if (this.current_page == this.last_page) {
				uni.showToast({
					title: '暂无更多',
					duration: 2000,
					icon: 'none'
				});
				this.loadStatus = "nomore"
			} else {
				++this.current_page
				this.modulelist()
			}

		},
		methods: {
			// cardSwiper
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},
			/* 瀑布流*/
			// 获取随机数据
			getRandomData() {
				this.loadStatus = 'loading'
				for (let i = 0; i < this.moduleList.length; i++) {
					let index = this.$t.number.randomInt(0, this.moduleList.length - 1)
					let item = this.moduleList[index]
					this.list.push(item)
				}
			},
			// 瀑布流加载完毕事件
			handleWaterFallFinish() {
				this.loadStatus = 'loadmore'
			},
			//模板列表
			modulelist(categoryId = '', erjifenlei = '', name = '') {
				this.loadStatus = 'loading'
				getmodulelist({
					page: this.current_page,
					categoryId,
					erjifenlei,
					name
				}).then((result) => {
					if(this.current_page==1){
						//当前
						this.current_page = result.data.list.current_page
						//最后
						this.last_page = result.data.list.last_page
						this.moduleList = result.data.list.data
						this.getRandomData()
						this.handleWaterFallFinish()
					}else{
						this.moduleList = this.moduleList.concat(result.data.list.data)
					}
				})
			},
			// 跳转
			tn(e) {
		
				uni.navigateTo({
					url: e,
				});
			},

		}
	}
</script>

<style lang="scss" scoped>
	.discovery {
		max-height: 100vh;
	}

	/* 底部安全边距 start*/
	.tn-tabbar-height {
		min-height: 120rpx;
		height: calc(140rpx + env(safe-area-inset-bottom) / 2);
		height: calc(140rpx + constant(safe-area-inset-bottom));
	}

	/* 自定义导航栏内容 start */
	.custom-nav {
		height: 100%;

		&__back {
			margin-left: 30rpx;
			margin-top: 5rpx;
			font-size: 40rpx;
			flex-basis: 5%;
			width: 100rpx;
			position: absolute;
		}
	}



	/* 瀑布流*/
	.product__item {
		background-color: #FFFFFF;
		overflow: hidden;
		margin: 0 10rpx;
		margin-bottom: 10rpx;
		// box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);

		.item {

			/* 图片 start */
			&__image {
				width: 100%;
				height: auto;
				background-color: #FFFFFF;
				border: 1rpx solid #F8F7F8;
				border-radius: 10rpx;
				overflow: hidden;
			}

			/* 图片 end */

			/* 内容 start */
			&__data {
				padding: 14rpx 0rpx;
			}

			/* 标题 start */
			&__title-container {
				text-align: justify;
				line-height: 38rpx;
				vertical-align: middle;
			}

			&__store-type {
				height: 28rpx;
				font-size: 20rpx;
				position: relative;
				display: inline-flex;
				align-items: center;
				justify-content: center;
				padding: 4rpx;
				border-radius: 6rpx;
				white-space: nowrap;
				text-align: center;
				top: -2rpx;
				margin-right: 6rpx;
			}

			&__title {
				font-size: 30rpx;
			}

			/* 标题 end */

			/* 标签 start */
			&__tags-container {
				display: flex;
				flex-direction: row;
				flex-wrap: nowrap;
				align-items: center;
				justify-content: flex-start;
			}

			&__tag {
				margin: 10rpx;
				color: #7C8191;
				background-color: #F3F2F7;
				padding: 4rpx 14rpx 6rpx;
				border-radius: 10rpx;
				font-size: 20rpx;

				&:first-child {
					margin-left: 0rpx !important;
				}
			}

			/* 标签 end */

			/* 价格 start */
			&__price-container {
				font-size: 24rpx;
				color: #E83A30;
				font-weight: bold;
			}

			&__price {
				&--unit {}

				&--integer {
					font-size: 38rpx;
				}

				&--decimal {}
			}

			/* 价格 end */
			/* 内容 end */
		}
	}
</style>